package com.epic.followup.controller.wechat;

import javax.servlet.http.HttpSession;

import com.epic.followup.service.wechat.WechatPatientDiaryService;
import com.epic.followup.temporary.DealMessageResponse;
import com.epic.followup.temporary.wechat.patient.diary.diaryIdRequest;
import com.epic.followup.temporary.wechat.patient.diary.getAllMoodsResponse;
import com.epic.followup.temporary.wechat.patient.diary.getAllPatientDiaryResponse;
import com.epic.followup.temporary.wechat.patient.diary.getPatientDiaryResponse;
import com.epic.followup.temporary.wechat.patient.diary.savePatientDiaryRequest;
import com.epic.followup.temporary.wechat.patient.diary.savePatientDiaryResponse;
import com.epic.followup.temporary.wechat.patient.diary.upLoadDiaryImgResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

@Controller
@RequestMapping("wechat/diary")
public class WechatPatientDiaryController {

    @Autowired
    private WechatPatientDiaryService wechatPatientDiaryService;

    @RequestMapping(value = "/uploadDiaryImg", method = RequestMethod.POST)
    @ResponseBody
    public upLoadDiaryImgResponse uploadDiaryImg(@RequestParam MultipartFile file){

        return wechatPatientDiaryService.uploadDiaryImg(file);
    }

    @RequestMapping(value = "/saveDiary", method = RequestMethod.POST)
    @ResponseBody
    public savePatientDiaryResponse saveDiary(HttpSession session, @RequestBody savePatientDiaryRequest saveDiaryRequest){

        String phone = session.getAttribute("phone").toString();

        return wechatPatientDiaryService.saveDiary(phone, saveDiaryRequest);
    }

    @RequestMapping(value = "/getDiary", method = RequestMethod.POST)
    @ResponseBody
    public getPatientDiaryResponse getDiary(@RequestBody diaryIdRequest diaryIdRequest){

        return wechatPatientDiaryService.getPatientDiaryById(diaryIdRequest);
    }

    @RequestMapping(value = "/deleteDiary", method = RequestMethod.POST)
    @ResponseBody
    public DealMessageResponse deleteDiary(@RequestBody diaryIdRequest diaryIdRequest){

        return wechatPatientDiaryService.delPatientDiaryById(diaryIdRequest);
    }

    @RequestMapping(value = "/getAllDiaries", method = RequestMethod.POST)
    @ResponseBody
    public getAllPatientDiaryResponse getAllDiaries(HttpSession session){
        return wechatPatientDiaryService.getAllPatientDiary((String)session.getAttribute("phone"));
    }

    @RequestMapping(value = "/getMood", method = RequestMethod.POST)
    @ResponseBody
    public getAllMoodsResponse getAllMoods(HttpSession session){
        return wechatPatientDiaryService.getAllPatientMoods((String)session.getAttribute("phone"));
    }
}
